package com.company.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import com.company.aspect.annotation.LogMethod;
import com.company.aspect.annotation.OperationType;
import com.company.dao.Employee;
import com.company.dao.EmployeeDAO;
import com.company.dao.User;
import com.company.dao.UserDAO;
import com.company.exception.DAOException;
import com.company.exception.ServiceException;

@Transactional 
public class ServiceImpl implements Service {

	@Autowired
	private UserDAO userDAO;
	
	@Autowired
	private EmployeeDAO employeeDAO;
		

	@Override	
	@LogMethod(type=OperationType.SAVE)	
	public User saveUser(User user, Employee employee) throws ServiceException, DAOException {
		employeeDAO.save(employee);
		
		return userDAO.save(user); 
	}

	@Override
	@LogMethod(type=OperationType.GET)
	public User findUser(long id) throws ServiceException, DAOException {
		return userDAO.findById(id); 
	}	
}
